﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using PagedList;
using System.Web.Mvc;
using EventPlanner.Models;
using System.Data.Objects;
using System.Data.Entity.Infrastructure;

namespace EventPlanner.Controllers
{ 
    public class AuditController : Controller
    {        
        private readonly IEventPlannerContext _db;

        public AuditController(IEventPlannerContext db) { _db = db; }

        // GET: /Audit/
        [Authorize(Roles = "Administrator")]
        public ViewResult Index(int? page)
        {
            int pageSize = 10;
            int pageNumber = (page ?? 1);


            return View(_db.AuditInfo.OrderByDescending(item => item.id).ToPagedList(pageNumber, pageSize));
        }

        //
        // GET: /Audit/Details/5

        public ViewResult Details(int id)
        {
            AuditInfo auditinfo = _db.AuditInfo.Find(id);
            return View(auditinfo);
        }

        //
        // GET: /Audit/Delete/5
 
        public ActionResult Delete(int id)
        {
            AuditInfo auditinfo = _db.AuditInfo.Find(id);
            return View(auditinfo);
        }

        //
        // POST: /Audit/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            AuditInfo auditinfo = _db.AuditInfo.Find(id);
            _db.AuditInfo.Remove(auditinfo);
            _db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            ((EventPlannerContext)_db).Dispose();
            base.Dispose(disposing);
        }
    }
}